<?php

namespace App\Http\Controllers\Api\Rbac;

use App\Http\Controllers\Controller;
use App\Rep\Rbac\RoleRep;
use Illuminate\Http\Request;

class Role extends Controller
{
    protected $rep;

    public function __construct(Request $request)
    {
        $this->rep = new RoleRep();
    }
    //角色管理
    public function getRoleList(Request $request){
        $params = $request->all();
        $list = $this->rep->roleListRep($params);
        return re(0,$list,'success');
    }

    //添加角色
    public function createRole(Request $request){
        $params = $request->all();
        $data = $this->rep->createRoleRep($params);
        return re(0,$data,'success');
    }
    //删除角色
    public function delRole(Request $request){
        $params = $request->all();
        $data = $this->rep->delRoleRep($params);
        return re(0,$data,'success');
    }

    public function setRoleStatus(Request $request){
        $params = $request->all();
        $data = $this->rep->setRoleStatusRep($params);
        return re(0,$data,'success');
    }

    //分配权限
    public function allocationNode(Request $request){
        $params = $request->all();
        $data = $this->rep->allocationNodeRep($params);
        return re($data['code'],$data['data'],$data['msg']);
    }

    //获取角色已分配的权限(全部权限)
    public function getRoleNodeList(Request $request){
        $params = $request->all();
        $roles_id = $params['roles_id'];
        $data = $this->rep->getRoleNodeListRep($roles_id);
        return re(0,$data,'success');
    }
//
    /**获取角色已分配的权限(仅分配权限)**/
    public function getRoleNodeInfo(Request $request){
        $params = $request->all();
        $role_id = $params['roles_id'];
        $data = $this->rep->getRoleNodeInfoRep($role_id);
        return re(0,$data,'success');
    }

    /**
     * 获取角色为【业务员】的账号列表
     */
    public function getYeWuYuanList(Request $request){
        $params = $request->all();
        $data = $this->rep->getYeWuYuanListRep($params);
        return re(0,$data,'success');
    }

    /**
     * 获取角色为【员工】的账号列表
     */
    public function getYuanGongList(Request $request){
        $params = $request->all();
        $data = $this->rep->getYuanGongListRep($params);
        return re(0,$data,'success');
    }


}
